package com.android.gardensnake;

import java.util.Random;

import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.text.InputType;
import android.view.Gravity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.ToggleButton;

public class TextPlay extends Activity implements View.OnClickListener {
	Button chkCmd;
	ToggleButton tbPassToggle;
	EditText etInput;
	TextView tvDisplay;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.text);
		
		baconAndEggs();
		
		tbPassToggle.setOnClickListener(this);
		chkCmd.setOnClickListener(this);
	}

	private void baconAndEggs() {
		// TODO Auto-generated method stub
		chkCmd = (Button) findViewById(R.id.bResults);
		tbPassToggle = (ToggleButton) findViewById(R.id.tbTryCommand);
		etInput = (EditText) findViewById(R.id.etCommands);
		tvDisplay = (TextView) findViewById(R.id.tvResults);
	}

	public void onClick(View v) {
		// TODO Auto-generated method stub
		switch(v.getId()) {
		case R.id.bResults:
			String strCheck = etInput.getText().toString();
			tvDisplay.setText(strCheck);
			if (strCheck.contentEquals("left")) {
				tvDisplay.setGravity(Gravity.LEFT);
			} else if (strCheck.contentEquals("center")) {
				tvDisplay.setGravity(Gravity.CENTER);
			} else if (strCheck.contentEquals("right")) {
				tvDisplay.setGravity(Gravity.RIGHT);
			} else if (strCheck.contentEquals("blue")) {
				tvDisplay.setTextColor(Color.BLUE);
			} else if (strCheck.contains("WTF")) {
				Random rdCrazy = new Random();
				tvDisplay.setText("WTF");
				tvDisplay.setTextSize(rdCrazy.nextInt(75));
				tvDisplay.setTextColor(Color.rgb(rdCrazy.nextInt(265), rdCrazy.nextInt(265), rdCrazy.nextInt(265)));
				switch(rdCrazy.nextInt(3)) {
				case 0: 
					tvDisplay.setGravity(Gravity.LEFT);
					break;
				case 1:
					tvDisplay.setGravity(Gravity.CENTER);
					break;
				case 2:
					tvDisplay.setGravity(Gravity.RIGHT);
					break;
				}
			} else {
				tvDisplay.setText("Invalid");
				tvDisplay.setGravity(Gravity.CENTER);
			}
			break;
		case R.id.tbTryCommand:
			if (tbPassToggle.isChecked()) {
				etInput.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
			} else {
				etInput.setInputType(InputType.TYPE_CLASS_TEXT);
			}
			break;
		}
	}
}
